#include "CommandHistory.h"


//@ author A0105541U
CommandHistory::CommandHistory(){
	numCommand = 0;
	commandRecords.clear();
};

//@ author A0105541U
void CommandHistory::addCommand(Cmd* givenCommand) {
	if (numCommand < commandRecords.size()) {
		commandRecords.erase(commandRecords.begin()+numCommand, commandRecords.end());
	}
	commandRecords.push_back(givenCommand);
	numCommand = commandRecords.size();
	
}

//@ author A0105541U
bool CommandHistory::undo(int num) {
	if (numCommand <= num) {
		num = numCommand;
	}
	numCommand = numCommand - num;
	return true;
}

//@ author A0105541U
int CommandHistory::getNumCommand() {
	return numCommand;
}

//@ author A0105541U
bool CommandHistory::redo(int num) {
	numCommand = numCommand + num;

	if (numCommand > commandRecords.size()) {
		numCommand = commandRecords.size();
	}

	return true;
}

// @author A0105541U
Cmd* CommandHistory::getCommand(int index) {
	assert (index >= 0 && index < commandRecords.size());
	return commandRecords.at(index);
}


